<template>
    <admin-container :show-back="false" :loading="loading">
        <k-class-manager :data="items" :handler="handler"/>
    </admin-container>
</template>

<script lang="ts">
import { Vue, Component } from 'vue-property-decorator';
import AdminContainer from '@/components/admin-container.vue';
import { DialogFormItem } from '@/store/dialog';
import { ArticleCategoryModel } from '../model';
import { deleteArticleCate, getArticleCates } from '@/views/article/service';
import KClassManager from '@/components/class-manager/index.vue';

@Component({
    components: {
        KClassManager,
        AdminContainer
    }
})
export default class Article extends Vue {
    items: ArticleCategoryModel[] = [];
    loading: boolean = true;
    handler: any = {
        // 删除
        async remove(data: any) {
            return await deleteArticleCate([data.id]);
        },
        // 编辑
        async edit(data: ArticleCategoryModel) {
            console.log('da', data);
            return {
                name: 'we'
            }
        }
    };
    dialog: {[key: string]: DialogFormItem[]} = {
        'add|edit': [
            { prop: 'id', type: 'hidden' },
            { label: '分类名称', prop: 'name', required: true },
        ],
    };

    async mounted() {
        this.loading = true;
        try {
            this.items = this.$array.tree(await getArticleCates());
        } finally {
            this.loading = false;
        }
    }

}
</script>
